//
//  SLTabBarController.swift
//  SLBlog
//
//  Created by 盼 on 2017/11/23.
//  Copyright © 2017年 pan. All rights reserved.
//

import UIKit

class SLTabBarController: UITabBarController {
    
   @objc private func plusBtnDidClick() {
        
        print("plusbtn did click.....")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //自定义tabbar
        let tabBar = SLTabBar()
        setValue(tabBar, forKey: "tabBar")
        tabBar.plusBtn.addTarget(self, action: #selector(SLTabBarController.plusBtnDidClick), for: UIControlEvents.touchUpInside)
        
        
        setupChildViewController(controller: SLHomeViewController(), title: "微博", image: "forum_not_selected", selectedImage: "forum_selected", visitorInfo: ["imageName":"","tipTitle":""])
        setupChildViewController(controller: SLMessageViewController(), title: "消息", image: "message_not_selected", selectedImage: "message_selected",visitorInfo: ["imageName":"visitordiscover_image_message","tipTitle":"登录后，别人评论的你的微博，给你发消息，都会在这里收到通知"])
        
        setupChildViewController(controller: SLDiscoverViewController(), title: "发现", image: "new_not_selected", selectedImage: "new_selected",visitorInfo: ["imageName":"visitordiscover_image_message","tipTitle":"登录后，来看看这里哟有什么惊喜吧"])
        setupChildViewController(controller: SLProfileViewController(), title: "我", image: "me_not_selected", selectedImage: "me_selected",visitorInfo: ["imageName":"visitordiscover_image_profile","tipTitle":"登录后，你的微博、相册、个人资料都会显示在这里，展示给别人"])
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension SLTabBarController {
    
    func setupChildViewController(controller: SLBaseViewController, title: String, image: String, selectedImage: String, visitorInfo:[String :String])
    {
        controller.tabBarItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor:UIColor.red], for: .selected)
        controller.tabBarItem.title = title
        controller.tabBarItem.image = UIImage(named: image)
        controller.tabBarItem.selectedImage = UIImage(named: selectedImage)
        controller.visitorInfoDict = visitorInfo
        
        let nav = SLNavigationController(rootViewController: controller)
        
        self.addChildViewController(nav)
    }
}
